package net.babypai;

import java.util.Timer;
import java.util.TimerTask;

import net.babypai.common.Constants;



import android.app.Activity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.RelativeLayout;

public class MyMenuDialog  extends Activity implements OnClickListener {
	
	private RelativeLayout my_menu_rl;
	private String cate;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		getCate();
		if(cate.equals(Constants.MENU_HOMECATE)){
			setContentView(R.layout.mymenu_home_dialog);
		}else if(cate.equals(Constants.MENU_USERCATE)){
			setContentView(R.layout.mymenu_user_dialog);
		}
		setView();
		setAnimIn();
	}
	
	private void getCate(){
		cate = getIntent().getStringExtra("cate");
	}
	
	private void setView(){
		my_menu_rl = (RelativeLayout) findViewById(R.id.my_menu_rl);
		if(cate.equals(Constants.MENU_HOMECATE)){
			setHomeView();
		}else if(cate.equals(Constants.MENU_USERCATE)){
			
		}
		
	}
	
	private void setHomeView(){
		
	}
	
	private void setAnimIn(){
		Animation scale = AnimationUtils.loadAnimation(
				MyMenuDialog.this, R.anim.rotate_anim_in);
		my_menu_rl.startAnimation(scale);
	}
	
	private void setAnimOut(){
		Animation scale = AnimationUtils.loadAnimation(
				MyMenuDialog.this, R.anim.rotate_anim_out);
		my_menu_rl.startAnimation(scale);
		
		Timer tExit = new Timer();
		TimerTask task;
		task = new TimerTask() {
			@Override
			public void run() {
				MyMenuDialog.this.finish();
			}
		};
		tExit.schedule(task, 1000);
	}

	@Override
	public boolean onTouchEvent(MotionEvent event){
		setAnimOut();
		return true;
	}

	@Override
	public void onClick(View v) {
		int id = v.getId();
		switch (id) {
		default:
			break;
		}
		
	}
	
	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		// TODO Auto-generated method stub
		if (keyCode == KeyEvent.KEYCODE_BACK) {
			setAnimOut();
		}
		return false;
	}
}